package com.lyf.scm.plan.domain.remote.transaction.facade;

import com.alibaba.fastjson.JSON;
import com.lyf.scm.common.enums.ResponseMsg;
import com.lyf.scm.plan.domain.remote.transaction.TransactionRemote;
import com.lyf.scm.plan.domain.remote.transaction.dto.NewPlanDTO;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 交易中心
 *
 * @author huangtao
 * @date 2020/09/18
 */
@Slf4j
@Service
public class TransactionFacade {

    @Resource
    private TransactionRemote transactionRemote;

    public Response<String> importJoinList(List<NewPlanDTO> newPlanList) {
        log.info("推送加盟新店新品计划数据出参：{}", JSON.toJSONString(newPlanList));
        Response<String> response = transactionRemote.importJoinList(newPlanList);
        log.info("推送加盟新店新品计划数据返回值：{}", JSON.toJSONString(response));
        if (!ResponseMsg.SUCCESS.getCode().equals(response.getCode())) {
            throw new RomeException(ResponseMsg.EXCEPTION_2007.getCode(), ResponseMsg.EXCEPTION_2007.getMsg() + response.getMsg());
        }
        return response;
    }

    public Response<String> importDirectlyList(List<NewPlanDTO> newPlanList) {
        log.info("推送直营新店新品计划数据出参：{}", JSON.toJSONString(newPlanList));
        Response<String> response = transactionRemote.importDirectlyList(newPlanList);
        log.info("推送直营新店新品计划数据返回值：{}", JSON.toJSONString(response));
        if (!ResponseMsg.SUCCESS.getCode().equals(response.getCode())) {
            throw new RomeException(ResponseMsg.EXCEPTION_2007.getCode(), ResponseMsg.EXCEPTION_2007.getMsg() + response.getMsg());
        }
        return response;
    }
}
